Exercise 2

Ward B. Eiling

Requirements

Create a presentation about any topic you like that consists of at least 7 slides and includes all of the following:

  • a logo

  • a centered still figure

  • an interactive table

  • a moving figure, interactive figure or movie

  • a 2-column slide

  • an aligned multi-row equation

  • a citation and reference list

  • a bibliographic reference

  • r-code, displayed but not executed

  • cached and labeled r-code (may overlap with the next requirement)

  • r-code, executed, but not displayed (e.g. a figure generation)

  • an renv reproducible enviroment

Centered Still Figure

This summer I went on a hike in Austria, where I took the following picture.

Centered Still Figure: Holiday Picture

Interactive table

Let’s make an interactive table of the Boston dataset from the MASS package.

library(MASS)
library(DT)
library(tidyverse)

Boston %>%
  datatable(options = list(pageLength = 10))

Interactive figure with cached and labeled r-code

Let’s make a moving figure of the iris dataset.

```{r}
#| code-line-numbers: true
#| label: moving figure
#| cache: true

library(ggplot2)
library(plotly)

plot  <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
            geom_point() +
            geom_smooth(se = TRUE, method = lm) +
            theme_minimal() +
            ggtitle("Iris dataset")
plot %>% ggplotly()
```

2 Column slide: aligned multi-row equation

everything left-aligned:

We may compute a, b, and c as follows:

\(\begin{align} a &= 0+1 \\ b &= 2+3 \\ c &= 4+5 \end{align}\)

where \(k\) is the number of parameters and \(L\) is the likelihood.

everything centered:

We may compute a, b, and c as follows:

\(\begin{align} a &= 0+1 \\ b &= 2+3 \\ c &= 4+5 \end{align}\)

where \(k\) is the number of parameters and \(L\) is the likelihood.

R-code: two columns

displayed but not executed r-code

```{r}
#| code-line-numbers: true
#| label: r-code displayed but not executed
#| eval: false

print("Oops, it didn't execute the r-code!")
```

executed but not displayed r-code

[1] "Oops, it didn't show anything!"

Citation

In this presentation, we will use the lme4 package (Bates et al. 2015) to fit a linear mixed model.

Code
# Fit a mixed linear model with lme4
library(lme4)
mlm <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
summary(mlm)
Linear mixed model fit by REML ['lmerMod']
Formula: Reaction ~ Days + (Days | Subject)
   Data: sleepstudy

REML criterion at convergence: 1743.6

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-3.9536 -0.4634  0.0231  0.4634  5.1793 

Random effects:
 Groups   Name        Variance Std.Dev. Corr
 Subject  (Intercept) 612.10   24.741       
          Days         35.07    5.922   0.07
 Residual             654.94   25.592       
Number of obs: 180, groups:  Subject, 18

Fixed effects:
            Estimate Std. Error t value
(Intercept)  251.405      6.825  36.838
Days          10.467      1.546   6.771

Correlation of Fixed Effects:
     (Intr)
Days -0.138

renv reproducible environment

Let’s create a reproducible environment with the renv package.

```{r}
#| code-line-numbers: true
#| label: renv reproducible environment

library(renv)
renv::init()
```
- Linking packages into the project library ... [5/130] [6/130] [7/130] [8/130] [9/130] [10/130] [11/130] [12/130] [13/130] [14/130] [15/130] [16/130] [17/130] [18/130] [19/130] [20/130] [21/130] [22/130] [23/130] [24/130] [25/130] [26/130] [27/130] [28/130] [29/130] [30/130] [31/130] [32/130] [33/130] [34/130] [35/130] [36/130] [37/130] [38/130] [39/130] [40/130] [41/130] [42/130] [43/130] [44/130] [45/130] [46/130] [47/130] [48/130] [49/130] [50/130] [51/130] [52/130] [53/130] [54/130] [55/130] [56/130] [57/130] [58/130] [59/130] [60/130] [61/130] [62/130] [63/130] [64/130] [65/130] [66/130] [67/130] [68/130] [69/130] [70/130] [71/130] [72/130] [73/130] [74/130] [75/130] [76/130] [77/130] [78/130] [79/130] [80/130] [81/130] [82/130] [83/130] [84/130] [85/130] [86/130] [87/130] [88/130] [89/130] [90/130] [91/130] [92/130] [93/130] [94/130] [95/130] [96/130] [97/130] [98/130] [99/130] [100/130] [101/130] [102/130] [103/130] [104/130] [105/130] [106/130] [107/130] [108/130] [109/130] [110/130] [111/130] [112/130] [113/130] [114/130] [115/130] [116/130] [117/130] [118/130] [119/130] [120/130] [121/130] [122/130] [123/130] [124/130] [125/130] [126/130] [127/130] [128/130] [129/130] [130/130] Done!
The following package(s) will be updated in the lockfile:

# CRAN -----------------------------------------------------------------------
- askpass         [* -> 1.2.0]
- backports       [* -> 1.4.1]
- base64enc       [* -> 0.1-3]
- bit             [* -> 4.0.5]
- bit64           [* -> 4.0.5]
- blob            [* -> 1.2.4]
- boot            [* -> 1.3-28]
- brio            [* -> 1.1.4]
- broom           [* -> 1.0.5]
- bslib           [* -> 0.6.1]
- cachem          [* -> 1.0.8]
- callr           [* -> 3.7.5]
- cellranger      [* -> 1.1.0]
- cli             [* -> 3.6.2]
- clipr           [* -> 0.8.0]
- colorspace      [* -> 2.1-0]
- conflicted      [* -> 1.2.0]
- cpp11           [* -> 0.4.7]
- crayon          [* -> 1.5.2]
- crosstalk       [* -> 1.2.1]
- curl            [* -> 5.2.0]
- data.table      [* -> 1.15.2]
- DBI             [* -> 1.2.2]
- dbplyr          [* -> 2.4.0]
- desc            [* -> 1.4.3]
- diffobj         [* -> 0.3.5]
- digest          [* -> 0.6.34]
- dplyr           [* -> 1.1.4]
- DT              [* -> 0.32]
- dtplyr          [* -> 1.3.1]
- ellipsis        [* -> 0.3.2]
- evaluate        [* -> 0.23]
- fansi           [* -> 1.0.6]
- farver          [* -> 2.1.1]
- fastmap         [* -> 1.1.1]
- fontawesome     [* -> 0.5.2]
- forcats         [* -> 1.0.0]
- fs              [* -> 1.6.3]
- gargle          [* -> 1.5.2]
- generics        [* -> 0.1.3]
- ggplot2         [* -> 3.5.0]
- glue            [* -> 1.7.0]
- googledrive     [* -> 2.1.1]
- googlesheets4   [* -> 1.1.1]
- gtable          [* -> 0.3.4]
- haven           [* -> 2.5.4]
- highr           [* -> 0.10]
- hms             [* -> 1.1.3]
- htmltools       [* -> 0.5.7]
- htmlwidgets     [* -> 1.6.4]
- httpuv          [* -> 1.6.14]
- httr            [* -> 1.4.7]
- ids             [* -> 1.0.1]
- isoband         [* -> 0.2.7]
- jquerylib       [* -> 0.1.4]
- jsonlite        [* -> 1.8.8]
- knitr           [* -> 1.45]
- labeling        [* -> 0.4.3]
- later           [* -> 1.3.2]
- lattice         [* -> 0.20-45]
- lazyeval        [* -> 0.2.2]
- lifecycle       [* -> 1.0.4]
- lme4            [* -> 1.1-35.1]
- lubridate       [* -> 1.9.3]
- magrittr        [* -> 2.0.3]
- MASS            [* -> 7.3-56]
- Matrix          [* -> 1.6-5]
- memoise         [* -> 2.0.1]
- mgcv            [* -> 1.8-40]
- mime            [* -> 0.12]
- minqa           [* -> 1.2.6]
- modelr          [* -> 0.1.11]
- munsell         [* -> 0.5.0]
- nlme            [* -> 3.1-157]
- nloptr          [* -> 2.0.3]
- openssl         [* -> 2.1.1]
- pillar          [* -> 1.9.0]
- pkgbuild        [* -> 1.4.3]
- pkgconfig       [* -> 2.0.3]
- pkgload         [* -> 1.3.4]
- plotly          [* -> 4.10.4]
- praise          [* -> 1.0.0]
- prettyunits     [* -> 1.2.0]
- processx        [* -> 3.8.3]
- progress        [* -> 1.2.3]
- promises        [* -> 1.2.1]
- ps              [* -> 1.7.6]
- purrr           [* -> 1.0.2]
- R6              [* -> 2.5.1]
- ragg            [* -> 1.2.7]
- rappdirs        [* -> 0.3.3]
- RColorBrewer    [* -> 1.1-3]
- Rcpp            [* -> 1.0.12]
- RcppEigen       [* -> 0.3.4.0.0]
- readr           [* -> 2.1.5]
- readxl          [* -> 1.4.3]
- rematch         [* -> 2.0.0]
- rematch2        [* -> 2.1.2]
- renv            [* -> 1.0.9]
- reprex          [* -> 2.1.0]
- rlang           [* -> 1.1.3]
- rmarkdown       [* -> 2.26]
- rprojroot       [* -> 2.0.4]
- rstudioapi      [* -> 0.15.0]
- rvest           [* -> 1.0.4]
- sass            [* -> 0.4.8]
- scales          [* -> 1.3.0]
- selectr         [* -> 0.4-2]
- stringi         [* -> 1.8.3]
- stringr         [* -> 1.5.1]
- sys             [* -> 3.4.2]
- systemfonts     [* -> 1.0.5]
- testthat        [* -> 3.2.1]
- textshaping     [* -> 0.3.7]
- tibble          [* -> 3.2.1]
- tidyr           [* -> 1.3.0]
- tidyselect      [* -> 1.2.0]
- tidyverse       [* -> 2.0.0]
- timechange      [* -> 0.3.0]
- tinytex         [* -> 0.49]
- tzdb            [* -> 0.4.0]
- utf8            [* -> 1.2.4]
- uuid            [* -> 1.2-0]
- vctrs           [* -> 0.6.5]
- viridisLite     [* -> 0.4.2]
- vroom           [* -> 1.6.5]
- waldo           [* -> 0.5.2]
- withr           [* -> 3.0.0]
- xfun            [* -> 0.42]
- xml2            [* -> 1.3.6]
- yaml            [* -> 2.3.8]

The version of R recorded in the lockfile will be updated:
- R               [* -> 4.2.0]

- Lockfile written to "~/GitHub Projects/Markup-Languages/00_exercises/02_presentation/renv.lock".

References

Bates, Douglas, Martin Mächler, Ben Bolker, and Steve Walker. 2015. “Fitting Linear Mixed-Effects Models Using lme4.” Journal of Statistical Software 67 (1): 148. https://doi.org/10.18637/jss.v067.i01.